package com.powernobug.service.impl;

import com.powernobug.service.*;
import com.powernobug.bean.model.MarketIssue;
import com.powernobug.service.*;

import com.powernobug.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * @Author: 肖云戈
 * @CreateTime: 2024-08-30
 * @Description:
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    SystemConfigService systemConfigService;
    @Autowired
    MarketSpecificationService marketSpecificationService;
    @Autowired
    MarketIssueService marketIssueService;
    @Autowired
    MarketCollectService marketCollectService;



    @Override
    public Map<String, Object> getGoodsDetail(Integer id) {
        // 从配置信息中加载 是否分享 的开关
        Boolean isAutoCreateShareImage = (Boolean) systemConfigService.getSystemConfigs().get(Constant.CONFIG_SHARE);

        Future<List<Map<String, Object>>> task1 = marketSpecificationService.getSpecifMapByGoodId(id);
        Future<List<MarketIssue>> task2 = marketIssueService.getIssueList();
        Future<Integer> task3 = marketCollectService.getCollectCountByGoodId(id);
//        Future<List<Map<String, Object>>> task4 = marketSpecificationService.getSpecifMapByGoodId(id);
//        Future<List<Map<String, Object>>> task5 = marketSpecificationService.getSpecifMapByGoodId(id);
//        Future<List<Map<String, Object>>> task6 = marketSpecificationService.getSpecifMapByGoodId(id);
//        Future<List<Map<String, Object>>> task7 = marketSpecificationService.getSpecifMapByGoodId(id);
//        Future<List<Map<String, Object>>> task8 = marketSpecificationService.getSpecifMapByGoodId(id);
//        Future<List<Map<String, Object>>> task9 = marketSpecificationService.getSpecifMapByGoodId(id);
//        Future<List<Map<String, Object>>> task10 = marketSpecificationService.getSpecifMapByGoodId(id);


        Map<String, Object> result = new HashMap<>();
        try {
            result.put("specificationList", task1.get());
            result.put("issue", task2.get());
            result.put("userHasCollect", task3.get());
//            result.put("shareImage", task4.get());
//            result.put("comment", task5.get());
//            result.put("share", task6.get());
//            result.put("attribute", task7.get());
//            result.put("brand", task8.get());
//            result.put("productList", task9.get());
//            result.put("info", task10.get());
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }

        return result;
    }
}
